package cn.edu.scnu.semart.echats.service.impl;

import cn.edu.scnu.semart.echats.mapper.UserStatMapper;
import cn.edu.scnu.semart.echats.service.UserStatService;
import cn.edu.scnu.semart.vo.user.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class UserStatServiceImpl implements UserStatService {
    private final UserStatMapper userStatMapper;

    @Override
    public List<UserTrendVO> dailyCumulative() {
        return userStatMapper.dailyCumulative();
    }

    @Override
    public List<UserTypeRatioVO> typeRatio() {
        // 把数据库的 NORMAL/ADMIN 转中文
        return userStatMapper.typeRatio()
                .stream()
                .peek(r -> r.setName("NORMAL".equals(r.getName()) ? "普通用户" : "管理员"))
                .collect(Collectors.toList());
    }

    @Override
    public List<UserStatusRatioVO> statusRatio() {
        List<UserStatusRatioVO> list = userStatMapper.statusRatio();
        // 如果数据库写法已保证两条，可直接返回
        return list;
    }

    @Override
    public List<FollowDailyVO> followDaily() {
        return userStatMapper.followDaily();
    }

    @Override
    public GraphVO graphData() {
        GraphVO vo = new GraphVO();
        vo.setNodes(userStatMapper.graphNodes());
        vo.setLinks(userStatMapper.graphLinks());
        return vo;
    }
}